@extends('admin.common.main')

@section('cnt')
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 权限管理
        <span class="c-gray en">&gt;</span> 添加权限
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>


    <article class="page-container">
        {{--引用验证--}}
        @include('admin.common.validate')
        @include('admin.common.msg')

        <form action="{{route('admin.auth.store')}}" method="post" class="form form-horizontal" id="form-member-add" @submit.prevent="submit">
            @csrf

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>权限名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" v-model="info.auth_name" placeholder="">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>上级权限：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width: 300px">
                        <select class="select" @change="change">
                            <option value="0" selected>===顶级菜单===</option>
                            @foreach($data as $v)
                                <option value="{{$v['id']}}">{{$v['auth_name']}}</option>
                                @foreach($v['son'] as $v1)
                                    <option value="{{$v1['id']}}">|--{{$v1['auth_name']}}</option>
                                @endforeach
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否菜单权限：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input  type="radio" value="1" v-model="info.is_menu" >
                        <label for="sex-1">是</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" value="0" v-model="info.is_menu">
                        <label for="sex-2">否</label>
                    </div>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>路由别名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" v-model="info.route_name" placeholder="" id="route_name" name="route_name">
                </div>
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="提交">
                </div>
            </div>

        </form>
    </article>
@endsection

@section('js')
    <script type="text/javascript" src="{{env('APP_URL')}}admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="{{env('APP_URL')}}admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="{{env('APP_URL')}}admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        new Vue({
            el: ".page-container",
            data: {
                info: {
                    _token: "{{csrf_token()}}",
                    auth_name: '',
                    pid: 0,
                    is_menu: 0,
                    route_name: '',
                },
            },
            methods:{
                change(evt) {
                    this.info.pid = evt.target.value;
                },
                async submit(evt) {
                    let url = evt.target.action;
                    let {code, msg} = await $.post(url, this.info);
                    if (code == 200) {
                        layer.msg(msg);
                        setTimeout(function () {
                            window.location.href = "{{route('admin.auth.index')}}"
                        }, 2000)
                    }
                    layer.msg(msg);
                }
            },
        });

    </script>
@endsection
